{{

  Computer Side (host)

}}

CON

  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000

  XBEE_DOUT_PIN = 10
  XBEE_DIN_PIN  = 11
  XBEE_MODE     = %0000
  XBEE_BAUD     = 9_600

  LED_PIN       = 0
  
obj

  xb    :       "FullDuplexSerial"  'comms to XBee.

var

  long  recv
  
pub go

  xb.start(XBEE_DOUT_PIN, XBEE_DIN_PIN, XBEE_MODE, XBEE_BAUD) 'start comms to XBee

  'main loop
  repeat

    recv := xb.rxcheck          'see if a byte is available, save result into 'recv'

    if recv == "?"              'if we received the correct prompt (= "?")
      TurnOnLED                 '  turn on the LED for a time
      xb.tx("!")                '  send back our response


pub TurnOnLED

  dira[LED_PIN]~~               'sets to output

  outa[LED_PIN] := 1            'sets pin high
  waitcnt(cnt + clkfreq)        'wait one second
  outa[LED_PIN] := 0            'turn it back off

  'all done here, return now